#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_CHATEVENT_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_CHATEVENT_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct EnterChatServerData : public QSharedData
{
		quint32 eventId;
		quint32 userFlags;
		quint32 ping;
		quint32 ipAddress;
		quint32 accountNumber;
		quint32 regAuthority;
		QByteArray user;
		QByteArray text;
};

class EnterChatServer : public Message
{
public:
	static const int id = 0x0a;
	BNCS_MESSAGE_SERVER_REGISTER(EnterChatServer, id);

public:
	QSharedDataPointer<EnterChatServerData> d;

public:
	EnterChatServer()
	{
		d = new EnterChatServerData();
	}
	
	virtual EnterChatServer* create()
	{
		return new EnterChatServer();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
	  return (d->uniqueName.size() + 1) + (d->stat.size() + 1) +
	    (d->accountName.size() + 1);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

	uniqueName = readStringFrom(ds);
	stat = readStringFrom(ds);
	accountName = readStringFrom(ds);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

	writeStringTo(ds, uniqueName);
	writeStringTo(ds, stat);
	writeStringTo(ds, accountName);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif
